from api import api


from .storeModel import StoreModel

from .user import StoreUser

selfStoreModels = {
    'resUsers': StoreUser
}


class Store(object):
    def __init__(self):
        self._models = {}

        for addon in api.addons:
            name = ''.join([wd.capitalize() for wd in addon._name.split('.')])
            name = name[0].lower() + name[1:]
            self._models[name] = addon

    def __getitem__(self, index):
        if self._models.get(index):
            myStoreModel = selfStoreModels.get(index, StoreModel)
            return myStoreModel(index, self._models.get(index))
        else:
            return None

    def __getattr__(self, index):
        if self._models.get(index):
            myStoreModel = selfStoreModels.get(index, StoreModel)
            return myStoreModel(index, self._models.get(index))
        else:
            return None


store = Store()
